package com.hungry.hfw.web;


import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.DispatcherServlet;
public class HungryDispatcherServlet extends DispatcherServlet 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1594880671747422238L;

	@Override
	public void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception 
	{
	try
		{
		 super.doDispatch(request, response);
		}
	catch(MultipartException e)
	{

		PrintWriter writer = response.getWriter();
		writer.println("{\"ERROR\":\"true\",\"ERROR_MSG\":\"File could not be uploaded.Please check whether the size of the uploaded file is greater than 16MB.\"}");
	}
	}
	
//	public HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {
//		if (this.getMultipartResolver() != null && this.getMultipartResolver().isMultipart(request)) {
//			if (request instanceof MultipartHttpServletRequest) {
//				logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " +
//						"this typically results from an additional MultipartFilter in web.xml");
//			}
//			else {
//				
//				return this.getMultipartResolver().resolveMultipart(request);
//				
//			}
//		}
//		// If not returned before: return original request.
//		return request;
//	}
	

}
